<?php


namespace app\api\model;


class Order extends BaseModel {

    protected $hidden = ['statis','commission'];

    public function getOrderList($openid,$page,$pagesize=''){
        $pagesize = $pagesize ? $pagesize : $this->pagesize;
        $start = ( $page - 1 ) * $pagesize;
        return self::field('o.ordersn,o.status,o.createtime,m.nickname,m.username')->alias('o')
                    ->join('member m','o.openid = m.openid')
                    ->where('o.openid',$openid)->order('o.createtime desc')->limit($start,$pagesize)->select();
    }


    public function getDetails($where){
        return self::with(['member','userDiscount','userDiscount.discount','orderGoods','orderGoods.disrule'])->where($where)->find();
    }


    public function orderGoods(){
        return $this->hasMany('Ordergoods','order_id','id','','LEFT')->field('order_id,name,price,dis_id');
    }


    public function userDiscount(){
        return $this->hasOne('Userdiscount','id','discount_id','','LEFT')->field('id,title');
    }


    public function member(){
        return $this->hasMany('Member','openid','openid','m','LEFT')->field('openid,username,nickname');

    }







}